<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.5.4/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="layui-elem-field layuimini-search">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    {{--<div class="layui-form-item">--}}
                        {{--<div class="layui-inline">--}}
                            {{--<label class="layui-form-label">角色名称</label>--}}
                            {{--<div class="layui-input-inline">--}}
                                {{--<input type="text" name="name" autocomplete="off" class="layui-input">--}}
                            {{--</div>--}}
                        {{--</div>--}}
                        {{--<div class="layui-inline">--}}
                            {{--<a class="layui-btn" lay-submit="" lay-filter="data-search-btn">搜索</a>--}}
                        {{--</div>--}}
                    {{--</div>--}}
                </form>
            </div>
        </fieldset>

        <div class="layui-btn-group">
            <button class="layui-btn data-add-btn">添加</button>
        </div>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter">
            <script type="text/html" id="currentTableBar">
                <a class="layui-btn layui-btn-xs data-role-edit" lay-event="edit">编辑</a>
                {{--<a class="layui-btn layui-btn-xs layui-btn-danger data-role-delete" lay-event="delete">删除</a>--}}
            </script>
        </table>
    </div>
</div>
<script src="/lib/layui-v2.5.4/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/admin/menu/data',
            cols: [[
                {field: 'id', width: 100, title: 'ID', sort: true},
                {field: 'title', width: 300, title: '标题'},
                {field: 'path', width: 300, title: '路径'},
                {field: 'level', width: 300, title: '级别'},
                {title: '操作', templet: '#currentTableBar', minWidth: 150, fixed: "right", align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true
        });


        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });

        $('#test2').on('click', function(){
            layer.open({
                type: 1,
                area: ['600px', '360px'],
                shadeClose: true, //点击遮罩关闭
                content: '\<\div style="padding:20px;">自定义内容\<\/div>'
            });

        });

        // 监听添加操作
        $(".data-add-btn").on("click", function () {
            // location.href = '/admin/menu/add'
            layer.open({
                offset: '100px', //右下角弹出
                type:2,
                title:'添加菜单',
                shadeClose:false,
                fix: true, //不固定
                maxmin: true,
                shade:0.4,
                area: ['850px', '500px'],
                content: '/admin/menu/add'
            });


        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                layer.open({
                    offset: '100px', //右下角弹出
                    type:2,
                    title:'编辑菜单',
                    shadeClose:false,
                    fix: true, //不固定
                    maxmin: true,
                    shade:0.4,
                    area: ['850px', '500px'],
                    content: '/admin/menu/edit?menu_id='+ data.id
                });

            } else if (obj.event === 'delete1') {
                layer.confirm('真的删除行么', function (index) {
                    $.ajax({
                        type: "post",
                        url: '/admin/role/del',
                        data: {role_id: data.id, _token: '{{csrf_token()}}'},
                        success: function (data) {
                            if (data.status == 2) {
                                layer.msg(data.msg, {icon: 5});//失败的表情
                                return;
                            } else {
                                layer.msg(data.msg, {
                                    icon: 6,//成功的表情
                                    time: 1000 //1秒关闭（如果不配置，默认是3秒）
                                }, function () {
                                    location.reload();
                                });
                            }
                        },

                    });

                    layer.close(index);
                });
            }
        });

    });
</script>
<script>

</script>

</body>
</html>